/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.kason.framework.protocol.dubbo;

import com.kason.framework.Invocation;
import com.kason.framework.regester.LocalRegester;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.lang.reflect.Method;

/**
 * @author 卢清波
 * @date 2021/2/20 10:59
 */
public class NettyServerHandler extends SimpleChannelInboundHandler<Invocation>
{

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Invocation invocation) throws Exception
    {
        // 本地获取服务
        Class aClass = LocalRegester.get(invocation.getInterfaceName());
        Method method = aClass.getMethod(invocation.getMethodName(), invocation.getArgTypes());
        Object invoke = method.invoke(aClass.newInstance(), invocation.getArgs());
        channelHandlerContext.writeAndFlush(invoke);
    }



}
